package com.springbootmybatis.controller;

import com.springbootmybatis.dto.LoginDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/home")
public class HomeController {

    private static Logger logger = LoggerFactory.getLogger(HomeController.class);

    @RequestMapping(value = "/login-get", method = RequestMethod.GET)
    public String loginGet(String username, String password){
        return username + ":" + password;
    }

    @RequestMapping(value = "/login-get-dto", method = RequestMethod.GET)
    public String loginGetDto(LoginDto loginDto){
        return loginDto.toString();
    }

    @RequestMapping(value = "/login-get-dto-rb", method = RequestMethod.GET)
    public String loginGetDtoRb(@RequestBody LoginDto loginDto){
        return loginDto.toString();
    }

    @RequestMapping(value = "/login-post", method = RequestMethod.POST)
    public String loginPost(String username, String password){
        return username + ":" + password;
    }

    @RequestMapping(value = "/login-post-dto", method = RequestMethod.POST)
    public String loginPostDto(LoginDto loginDto){
        return loginDto.toString();
    }

    @RequestMapping(value = "/login-post-dto-rb", method = RequestMethod.POST)
    public String loginPostDtoRb(@RequestBody LoginDto loginDto){
        return loginDto.toString();
    }

    @RequestMapping(value = "/upload")
    public String upload(MultipartFile file){
        return file.getOriginalFilename();
    }

    @RequestMapping(value = "/upload-post", method = RequestMethod.POST)
    public String uploadPost(MultipartFile file){
        return file.getOriginalFilename();
    }
}
